<template>
  <m-container class="main">
    <m-navbar title="系统入库单" background="#fff" :right="['more']" :more="more" @more="handleMore"> </m-navbar>

    <m-mescroll-uni
      ref="mescrollRef"
      :down="{ auto: false }"
      :up="upConfig"
      height="calc(100vh - 55px)"
      :fixed="false"
      @init="mescrollInit"
      @up="upCallback"
      @down="downCallback"
      background="linear-gradient(to bottom, #def2fc, #f2f9fd)"
    >
      <in-work-box-item v-for="(item, index) in list" :key="index" :modal="item" :dict-map="dictMap" />
    </m-mescroll-uni>
  </m-container>
</template>

<script>
import { router } from '@/router'
import { listWorkOrder } from '@/api/modules/workOrder'
import { getDicts } from '@/api/modules/dict'

export default {
  data() {
    return {
      visible: false,
      type: 'add',
      upConfig: {
        empty: {
          use: true,
          icon: require('@/static/empty.png'),
          tip: '暂无数据',
        },
      },
      mescrollObj: {},
      list: [],
      params: {
        pageNum: 1,
        pageSize: 10,
        platformType: 1,
      },
      dictMap: {},
      more: [
        { name: '历史工单', icon: 'order' },
        { name: '快速入库', icon: 'scan' },
      ],
    }
  },
  async onLoad() {
    const { map } = await getDicts('ims_order_source_type')
    this.dictMap = {
      map,
    }
  },
  methods: {
    handleMore(e, index) {
      router.push({
        name: e.name === '历史工单' ? 'InWorkHistory' : 'ScanSearch',
      })
    },
    mescrollInit(mescroll) {
      this.mescrollObj = mescroll
    },
    async upCallback(page) {
      this.params.pageNum = page.num
      await this.fetchData()
    },
    downCallback() {
      this.mescrollObj && this.mescrollObj.resetUpScroll()
    },
    async fetchData() {
      const { rows } = await listWorkOrder(this.params)
      this.mescrollObj.endSuccess(rows.length, rows.length === this.params.pageSize)
      this.list = this.params.pageNum === 1 ? rows : [...this.list, ...rows]
    },
  },
}
</script>

<style lang="scss" scoped></style>
